import { getTableHeight, changePagination, selectChange } from "@/utils/table";
import { edit, changeStatus, isDisplay, remoteMethod } from "@/utils/form";

import { authDelete, getUserList } from "@/api/auth";

export default {
  data() {
    return {
      multipleSelection: [],
      dataGrid: {
        visible: false,
        loading: false,
        changePagination: (pagination) => changePagination("dataGrid", this, pagination, this.search),
        selectChange: (multipleSelection) => selectChange("dataGrid", this, multipleSelection, this.search),
        height: getTableHeight("", "dataGrid", this, 290),
        columns: [
          {
            width: "230",
            label: "操作",
            action: true,
            fixed: "left",
            align: "center"
          },
          {
            label: "角色名称",
            prop: "name",
            align: "center"
          },
          {
            label: "角色人员",
            prop: "names",
            align: "center"
          },
          {
            label: "角色备注",
            prop: "remark",
            align: "center"
          }
        ],
        data: [],
        pagination: {
          hidden: 2,
          currentPage: 1,
          pageSizes: [50, 100, 150],
          pageSize: 50,
          total: 0,
          pageCount: 0
        },
        btnList: [
          {
            label: "编辑",
            hide: (row) => !row.sysFlag,
            mthods: (row) => {
              this.editForm.title[0] = "编辑角色";
              isDisplay("editForm", this, [1, 2], [0]);
              edit("editForm", this, "", row);
            },
            type: "text",
            hasPermission: "qm:auth:role:do"
          },
          {
            label: "配置权限",
            hide: (row) => !row.sysFlag,
            mthods: (row) => this.authorityManagement(row),
            type: "text",
            hasPermission: "qm:auth:role:do"
          },
          {
            label: "修改人员",
            hide: (row) => !row.sysFlag,
            mthods: (row) => {
              remoteMethod("editForm", "userIds", this, getUserList, "", ["name", "id"], "key", true);
              this.editForm.title[0] = "修改人员";
              isDisplay("editForm", this, [0], [1, 2]);
              edit("editForm", this, "", row);
            },
            type: "text",
            hasPermission: "qm:auth:role:do"
          },
          {
            label: "删除",
            mthods: (row) => changeStatus(row, authDelete, "确定删除?", this.search),
            type: "text",
            hide: (row) => row.name !== "systemAdmin" && row.name !== "sensitiveInfo",
            hasPermission: "qm:auth:role:do",
            style: {
              color: "#F56C6C"
            }
          }
        ]
      }
    };
  },
  methods: {
    // 权限配置
    authorityManagement(row) {
      this.permDialog = {
        roleId: row.id,
        show: true,
        row: row
      };
    }

  }
};

